package ch.jamme.impl;

import java.util.concurrent.*;

import ch.jamme.reference.*;

class XmlToObjectConsumer extends XmlToObjectConvertor implements Runnable {

	private BlockingQueue<XmlMarshallableReference> queue;

	XmlToObjectConsumer(MarshallerEngine marshallerEngine, BlockingQueue<XmlMarshallableReference> queue) {
		super(marshallerEngine);
		this.queue = queue;
	}
	
	public void run() {
		try {
			while (true) {
				XmlMarshallableReference reference = queue.take();
				if (reference.isVoid()) break; // A void reference is the poison pill that kills this thread
				populateObject(reference.getParentElement(), reference.getValue());
			}
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
	}
}
